package com.whw.springboot.walk.service.servicelmpl;

import com.whw.springboot.walk.entity.Goods;
import com.whw.springboot.walk.entity.Message;
import com.whw.springboot.walk.mapper.GoodsMapper;
import com.whw.springboot.walk.service.GoodsService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class GoodsServiceImpl implements GoodsService {

    @Resource
    private GoodsMapper goodsMapper;
    //>0?Message.success(null):Message.fail(null)

    @Override
    public Message<?> addGoods(Goods goods) {
        return goodsMapper.addGoods(goods)>0?Message.success(null):Message.fail(null);
    }

    @Override
    public Message<?> delGoods(String goodsId) {
        return goodsMapper.delGoodsByPrimaryKey(goodsId)>0?Message.success(null):Message.fail(null);
    }

    @Override
    public Message<?> updateGoods(Goods goods) {
        return goodsMapper.updateGoodsByPrimaryKey(goods)>0?Message.success(null):Message.fail(null);
    }

    @Override
    public Message<Goods> selectOneGoodsAndUserInfoByPrimaryKey(String goodsId) {
        return Message.success(null).add(goodsMapper.selectOneGoodsByPrimaryKey(goodsId));
    }

    @Override
    public Message<List<Goods>> selectGoodsByName(String goodName) {
        return Message.success(null).add(goodsMapper.selectGoodsByName(goodName));
    }

    @Override
    public Message<List<Goods>> selectAllGoods() {
        return Message.success(null).add(goodsMapper.selectAllGoods());
    }
}
